<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('IT成绩录入列表')" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>学号：</label>
                                <input type="text" name="stuId"/>
                            </li>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="stuName"/>
                            </li>
                            <li>
                                <label>实践环节类型：</label>
                                <select name="taskClass" th:with="type=${@dict.getType('sys_task')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}">
                                    </option>
                                </select>
                            </li>
                            <li>
                                <label>课题学期：</label>
                                <select name="taskTerm" th:with="type=${@dict.getType('sys_task_term')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}">
                                    </option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()">
                    <i class="fa fa-upload"></i> 批量导入
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-editable-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/teaItTask";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                modalName: "IT成绩录入",
                onEditableSave: onEditable,//行内编辑数据提交
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '学生课题序号',
                    visible: false
                },
                {
                    field: 'stuId',
                    title: '学号'
                },
                {
                    field: 'stuName',
                    title: '姓名'
                },
                {
                    field: 'stuClass',
                    title: '班级'
                },
                {
                    field: 'taskClass',
                    title: '实践环节类型'
                },
                {
                    field: 'score',
                    title: '成绩',
                    sortable: true,
                    editable : {
                        type : 'text',//弹框类型 文本
                        emptytext : "【指数】为空",//无值 提示文字
                        validate : function(value) {
                            //validate 弹框内容验证
                            //value 文本框内容
                            if (value.length == 0) {
                                return '指数不能为空';
                            }
                            if (value.length > 3) {
                                return "指数不能超过3个字符！";
                            }
                        }
                    }
                },]
            };
            $.table.init(options);
        });
        //行内编辑 提交数据
        function onEditable (field, row, oldValue, $el) {
            //这里不使用oldValue，而是取文内容  是因为：多次修改同一个元素值的话，oldValue会默认保存并使用上一次的值，所以，还是直接用元素文本比较保守(不适用于被简化的长文本)
            // var initValue = $el.html();
            $.ajax({
                type: "post",
                url: "/system/teaItTask/editableSave",//ajax提交数据接口    data封装各参数
                data: {
                    "keyValue": row.id,//row方式获取当前行对应的数据对象，点属性的方式获取对象属性值
                    "field": field,//当前被修改字段
                    "oldValue": oldValue,//表格列表显示的老数据值
                    "newValue": row[field]//行内编辑文本框内容
                },
                success: function (result) {
                    if (result.msg == "操作失败") {
                        $.modal.alertWarning("出现问题");
                    }
                    $.modal.closeLoading();
                }
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>
